package edu.chinasoft.listen02;


import javax.servlet.ServletContext;
import javax.servlet.ServletContextAttributeEvent;
import javax.servlet.ServletContextAttributeListener;


import org.apache.log4j.Logger;

//关于 ServeltContext生命周期的监听器
public class ServletContextAttributeListenerImp implements ServletContextAttributeListener {
	private Logger logger = Logger.getLogger(ServletContextAttributeListenerImp.class);
	//触发把元素添加到serveltcontext容器时
	@Override
	public void attributeAdded(ServletContextAttributeEvent arg0) {
		// TODO Auto-generated method stub
		logger.debug("ServletContextAttributeListenerImp>>attributeAdded  start……");
		logger.info("添加元素执行,添加的key值为："+arg0.getName()+",value值为："+arg0.getValue()+"。");
		logger.debug("ServletContextAttributeListenerImp>>attributeAdded  end……");
	}
	//触发把元素从serveltcontext容器删除时
	@Override
	public void attributeRemoved(ServletContextAttributeEvent arg0) {
		// TODO Auto-generated method stub
		logger.debug("ServletContextAttributeListenerImp>>attributeRemoved  start……");
		logger.info("移除元素执行,移除的key值为："+arg0.getName()+",value值为："+arg0.getValue()+"。");
		logger.debug("ServletContextAttributeListenerImp>>attributeRemoved  end……");

	}
	//触发修改serveltcontext容器里的元素时
	@Override
	public void attributeReplaced(ServletContextAttributeEvent arg0) {
		// TODO Auto-generated method stub
		logger.debug("ServletContextAttributeListenerImp>>attributeReplaced  start……");
		logger.info("替换元素执行,替换之前key值为："+arg0.getName()+",value值为："+arg0.getValue()+"。");
		ServletContext servletContext = arg0.getServletContext();
		logger.info("替换元素执行,替换之后key值为：key01,value值为："+servletContext.getAttribute("key01")+"。");
		logger.debug("ServletContextAttributeListenerImp>>attributeReplaced  end……");

	}
	
	
}
